#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 区间合并
/*
[1, 3]  [2, 6]

1 2 3 4 5 6 7 8 9
↑-↑ 
  ↑--↑  ↑-↑ ↑-↑
            ↑---↑    

    合并之后3个区间
*/
int n;
typedef pair<int, int> PII;
vector<PII> s;
// 贪心算法（区间贪心）
void merge(vector<PII> &segs)
{
    vector<PII> res;
    // 先以左端点排序 再以右端点排序
    sort(segs.begin(), segs.end());

    int st = -2e9, ed = -2e9;
    for(auto seg : segs)
        if(ed < seg.first)
        {
            if(st != -2e9) res.push_back({st, ed});
            st = seg.first, ed = seg.second;
        }
        else ed = max(ed, seg.second);
    if(st != -2e9) res.push_back({st, ed});

    segs = res;
}
int main()
{
    cin >> n;   
    for(int i = 0; i < n; i ++)
    {
        int l, r;
        cin >> l >> r;
        s.push_back({l,r});
    }
    merge(s);
    cout << s.size() << endl;
    return 0;
}